<template>
    <div class="ff-recommend-passage">
        <passage
            :get-data="getPassageData(1)"
            :pagination="false"
            title="预计本周到店商品"
            nodatatext="本周无到店的款"
            class="ff-recommend-passage-box"
        ></passage>
        <passage
            :get-data="getPassageData(2)"
            :pagination="false"
            title="预计下周到店商品"
            nodatatext="下周无到店的款"
            class="ff-recommend-passage-box"
        ></passage>
    </div>
</template>

<script>
    import passage from '@/views/recommend/childrenRoute/addOrReplace'
    export default {
        data() {
            return {
                getThisWeek: () => {},
                getNextWeek: () => {},
            }
        },
        components: {
            passage
        },
        methods: {
            /**
             * 获取换款数据列表(业务组件,数据耦合性较强)
             * @param
             * cb: 回调函数,用户返回处理后的数据  (具体可以看子组件的detail数据)
             **/
            getPassageData (status) {
                return (cb) => {
                    if(status === 1) this.getThisWeek = cb;
                    if(status === 2) this.getNextWeek = cb;
                }
            },
            /*获取数据*/
            getData () {
                this.$http({
                    url: '/api/SelPro/GetStrInStyList',
                    method: 'post',
                    data: {
                        strId: this.$store.state.userId
                    }
                }).then(res => {
                    let data = res.data;
                    if(data.code === 1) {
                        let next = data.data.find(n => n.weekType === 'week_next');
                        next = next? next.styListDts.map(obj => {
                            let imgList = obj.img? JSON.parse(obj.img) : [];
                            return Object.assign({
                                disabled: true,//是否禁用
                                ecode: obj.styCode,//款号
                                name: obj.styName,//款名称
                                imageUrl: imgList[0].URL,//商品主图
                                volume: obj.qtyRetail7D,//销量
                                arriveDate: obj.dateStrIn,//到店日期
                                presentPrice: obj.stdPrice === obj.retailPrice || obj.retailPrice === 0? obj.stdPrice : obj.retailPrice,//最终显示价格
                                showFocus: true,//显示收藏
                                focus: obj.isAtten === 1? true : false,//是否已收藏
                                focusSum: obj.attention,//收藏数量
                                inform: `${obj.lenName},${obj.slveLenName}`,//衣长,袖长
                                checked: false,//是否选中
                                imgList: imgList.map(img => {
                                    return {
                                        src: img.URL,
                                        active: false
                                    }
                                }),//小图集合
                            }, obj)
                        }) : [];
                        let now = data.data.find(n => n.weekType === 'week_now');
                        now = now? now.styListDts.map(obj => {
                            let imgList = obj.img? JSON.parse(obj.img) : [];
                            return Object.assign({
                                disabled: true,//是否禁用
                                ecode: obj.styCode,//款号
                                name: obj.styName,//款名称
                                imageUrl: imgList[0].URL,//商品主图
                                volume: obj.qtyRetail7D,//销量
                                arriveDate: obj.dateStrIn,//到店日期
                                presentPrice: obj.stdPrice === obj.retailPrice || obj.retailPrice === 0? obj.stdPrice : obj.retailPrice,//最终显示价格
                                showFocus: true,//显示收藏
                                focus: obj.isAtten === 1? true : false,//是否已收藏
                                focusSum: obj.attention,//收藏数量
                                inform: `${obj.lenName},${obj.slveLenName}`,//衣长,袖长
                                checked: false,//是否选中
                                imgList: imgList.map(img => {
                                    return {
                                        src: img.URL,
                                        active: false
                                    }
                                }),//小图集合
                            }, obj)
                        }) : [];
                        this.getThisWeek(now);
                        this.getNextWeek(next);
                    }else {
                        this.getThisWeek([]);
                        this.getNextWeek([]);
                    }
                }).catch(() => {
                    this.getThisWeek([]);
                    this.getNextWeek([]);
                })
            },
        },
        mounted () {
            this.getData();
        }
    }
</script>

<style type="text/less" lang="less">
.ff-recommend-passage {
    width: 100%;
    .ff-recommend-passage-box {
        border: 1px solid #DCDCDC;
        margin-bottom: 10px;
    }
}
</style>